package com.yunquan.ohana.entity

data class UserEntity(
    val id: String?,
    val deviceId: String?,
    val nickname: String?,
    val headImg: String?,
    val headImgUrl: String?,
    val email: String?,
)

class UserManager {
    companion object {
        val instance by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { UserManager() }
    }

    private var mUser: UserEntity? = null

    fun setUser(user: UserEntity) {
        this.mUser = user
    }

    fun getUser(): UserEntity? {
        return this.mUser
    }

    fun setNickname(nickname: String) {
        this.mUser = this.mUser?.copy(nickname = nickname)
    }

    fun setAvatar(avatar: String) {
        this.mUser = this.mUser?.copy(headImgUrl = avatar)
    }

    fun setEmail(email: String) {
        this.mUser = this.mUser?.copy(email = email)
    }

    fun clear(){
        this.mUser = null
    }
}